/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: RoleController
 * Author:   sky
 * Date:     2020/5/10 14:43
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package cn.szh.controller;


import cn.szh.domain.Role;
import cn.szh.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author sky
 * @create 2020/5/10
 * @since 1.0.0
 */
@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(){
        ModelAndView mv =new ModelAndView();
        List<Role> roles = roleService.findAll();
        mv.addObject("roleList",roles);
        mv.setViewName("role-list");
        return mv;
    }
    @RequestMapping("/findById.do")
    public ModelAndView findDetailById(@RequestParam(name = "id") Integer id){
        ModelAndView mv=new ModelAndView();
        Role role = roleService.findById(id);
        mv.addObject("role",role);
        mv.setViewName("role-show");
        return mv;
    }
   //添加（新建）角色信息
    @RequestMapping("/addRole.do")
    public String addRole(@RequestParam(name = "roleName")String roleName,
                          @RequestParam(name = "roleDesc")String roleDesc){
        roleService.addRole(roleName,roleDesc);

        return "redirect:/role/findAll.do";
       // return "redirect:findAll.do";  //都可以
    }
}
